package com.itc.bpm.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itc.bpm.bean.BpmModel;
import com.itc.bpm.bean.BpmProcessCategory;
import com.itc.bpm.dto.BpmProcessCategoryDto;
import com.itc.bpm.service.BpmProcessCategoryService;
import com.itc.common.core.domain.R;
import com.itc.common.core.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "流程分类管理接口")
@RestController
@Api(tags = "流程分类管理接口")
@RequestMapping("/bpm/category")
public class BpmProcessCategoryController {

    @Autowired
    BpmProcessCategoryService bpmProcessCategoryService;
    @PostMapping("/page")
    @ApiOperation(value = "流程模型分页")
    public R<Page<BpmProcessCategory>> getPage(@RequestBody BpmProcessCategory bpmFormDesign)
    {
        Page<BpmProcessCategory> page = new Page<>();
        page.setOptimizeCountSql(true);
        page.setSize(bpmFormDesign.getSize());
        page.setCurrent(bpmFormDesign.getCurrent());
        bpmFormDesign.setDelFlag(0);
        if(bpmFormDesign.getParentId()==null){
            bpmFormDesign.setParentId(0L);
        }
        LambdaQueryWrapper<BpmProcessCategory> queryWrapper = new LambdaQueryWrapper<>(bpmFormDesign).orderByAsc(BpmProcessCategory::getOrderNo);
        queryWrapper.eq(BpmProcessCategory::getDelFlag,0);
        Page<BpmProcessCategory> resultPage = bpmProcessCategoryService.page(page,queryWrapper);
        return R.ok(resultPage);
    }

    @ApiOperation(value = "新增/修改 分类")
    @PostMapping(value = "/add",consumes = "application/json")
    public R addCategory(@RequestBody BpmProcessCategory bpmModel){
        return bpmProcessCategoryService.addCategory(bpmModel);
    }

    @ApiOperation(value = "获取全部分类")
    @GetMapping("/all")
    public R<List<BpmProcessCategoryDto>> queryAll(){
        return bpmProcessCategoryService.queryAll();
    }



}
